package com.servlets.project.version;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.core.GlobalConstants;
import com.core.protocols.IServiceLayerDelegate;
import com.servicelayer.project.VersionListLayer;
import com.servlets.TaskTrackerServlet;

public class VersionDelete
        extends TaskTrackerServlet
        implements IServiceLayerDelegate {

    private HttpServletResponse postResponse = null;



    @Override
    public <T> void responseResponseItemsList ( final List <T> items,
                                                final Object request,
                                                final Exception exception ) {

        if ( postResponse == null ) {
            return;
        }

        if ( exception != null ) {

        }

        String redirection = null;
        redirection = String.format("%s", GlobalConstants.SERVLET_PROJECTLIST);

        if ( this.postResponse != null ) {
            try {
                this.postResponse.sendRedirect(redirection);
            } catch ( IOException e ) {
                e.printStackTrace();
            }
        }

    }

    private static final long serialVersionUID = 1L;



    @Override
    protected void doPost ( HttpServletRequest request,
                            HttpServletResponse response )
            throws ServletException, IOException {

        this.postResponse = response;

        String versionId = request.getParameter(GlobalConstants.SERVLET_PARAM_KEY);

        VersionListLayer versionListLayer = new VersionListLayer();
        versionListLayer.setLayerDelegate(this);
        versionListLayer.deleteObject(versionId);

    }



}
